import request from '@/utils/request.js'

/**
 * 获取频道列表
 */
export function getChannelList() {
    return request.get('/channel', {
        params: {
            methodName: 'getChannelList'
        }
    })
}

/**
 * 获取热榜标题
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getHotTitle() {
    return request.get('/news/hot', {
        params: {
            methodName: 'getHotTitle'
        }
    })
}

/**
 * 获取文章列表数据
 * @param page
 * @param size
 * @param title
 * @param channelId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getNewsList(page, size, title, channelId) {
    return request.get('/news/list', {
        params: {
            methodName: 'getNewsList',
            page: page,
            size: size,
            title: title,
            channelId: channelId
        }
    })
}

/**
 * 随机获热点文章数据
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getHotNewsList(size) {
    return request.get('/news/random', {
        params: {
            methodName: 'getHotNewsList',
            size: size
        }
    })
}

/**
 * 添加文章
 * @param newsForm
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function saveNews(newsForm) {
    return request.post('/publish', newsForm)
}

/**
 * 获取文章详情
 * @param newsId
 */
export function getDetailNews(newsId) {
    return request.get('/news/detail', {
        params: {
            methodName: 'getNewsDetail',
            newsId: newsId
        }
    })
}

/**
 * 添加评论
 */
export function addComment(comment) {
    return request.post('/comment', comment)
}

/**
 * 获取评论列表
 */
export function getCommentList(newsId, commentId) {
    return request.get('/comment/list', {
        params: {
            methodName: 'getCommentTree',
            newsId: newsId,
            commentId: commentId
        }
    })
}

/**
 * 获取一级评论列表
 * @param newsId
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getFirstCommentList(newsId) {
    return request.get('/comment/first', {
        params: {
            methodName: 'getFirstComment',
            newsId: newsId
        }
    })
}

/**
 * 获取个人作品列表
 * @param page
 * @param size
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function getPersonNewsList(page, size, searchParams) {
    return request.get('/news', {
        params: {
            page: page,
            size: size,
            title: searchParams?.title,
            name: searchParams?.name,
            startTime: searchParams?.searchTime[0],
            endTime: searchParams?.searchTime[1],
            methodName: 'getPersonWork'
        }
    })
}

/**
 * 删除作品
 * @param id
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export function removeNewsPerson(id) {
    return request.delete('/news', {
        params: {
            methodName: 'deleteWork',
            newsId: id
        }
    })
}

/**
 * 修改文章
 * @param addForm
 */
export function editNews(addForm) {
    return request.post('/update', addForm)
}


/**
 * 点赞
 * @param articleId
 */
export function loveArticleDetail(articleId) {
    return request.get('/love/like', {
        params: {
            articleId: articleId
        }
    })
}


/**
 * 取消点赞
 * @param articleId
 */
export function cancelLoveArticleDetail(articleId) {
    return request.get('/love/unlike', {
        params: {
            articleId: articleId
        }
    })
}




/**
 * 收藏
 * @param articleId
 */
export function collectArticleDetail(articleId) {
    return request.get('/collect', {
        params: {
            articleId: articleId
        }
    })
}


/**
 * 取消收藏
 * @param articleId
 */
export function cancelCollectArticleDetail(articleId) {
    return request.get('/uncollect', {
        params: {
            articleId: articleId
        }
    })
}


/**
 * 关注
 * @param userId
 */
export function concernUser(userId) {
    return request.get('/concern', {
        params: {
            concernUserId: userId
        }
    })
}


/**
 * 取消收藏
 * @param userId
 */
export function cancelConcernUser(userId) {
    return request.get('/unconcern', {
        params: {
            concernUserId: userId
        }
    })
}


/**
 * 是否关注
 * @param userId
 */
export function isConcernUser(userId) {
    return request.get('/isconcern', {
        params: {
            concernUserId: userId
        }
    })
}
